package org.chen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.chen.dto.TtsVoiceDTO;
import org.chen.entity.TtsVoice;
import org.chen.mapper.TtsVoiceMapper;
import org.chen.service.TtsVoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TtsVoiceServiceImpl extends ServiceImpl<TtsVoiceMapper, TtsVoice> implements TtsVoiceService {

    @Autowired
    private TtsVoiceMapper ttsVoiceMapper;

    @Override
    public List<TtsVoiceDTO> getAllVoices() {
        List<TtsVoice> voices = ttsVoiceMapper.selectList(null);
        return voices.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    @Override
    public List<TtsVoiceDTO> getVoicesByModelId(String modelId) {
        List<TtsVoice> voices = ttsVoiceMapper.findVoicesByModelId(modelId);
        return voices.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    private TtsVoiceDTO convertToDTO(TtsVoice voice) {
        TtsVoiceDTO dto = new TtsVoiceDTO();
        dto.setId(voice.getVoiceId());
        dto.setName(voice.getName());
        dto.setDescription(voice.getDescription());
        return dto;
    }
}